package com.Lyoto.core.enetity;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * @author Lyoto
 * @Description
 * @Date 2022-09-22 11:47
 * @Version
 **/
@Getter
@Setter
public class Result<T> implements Serializable {
    private int code;
    private String msg;
    private T data;
    
    private Result() {
        this(200, "成功", null);
    }
    
    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    
    public static <T> Result<T> suc() {
        return new Result<>();
    }
    
    public static <T> Result<T> suc(String msg) {
        return suc(msg,null);
    }
    
    public static <T> Result<T> suc(String msg, T data) {
        return new Result<>(200, msg, data);
    }
    
    public static <T> Result<T> fail(int code, String msg, T data) {
        return new Result<>(code, msg, data);
    }
    public static <T> Result<T> fail( String msg, T data) {
        return fail(400, msg, data);
    }
    
    public static <T> Result<T> fail(T data) {
        return fail("失败了", data);
    }
    public static <T> Result<T> fail() {
        return fail(null);
    }
    
}
